package com.fang.security.common.result;

import com.fang.security.common.base.ResultCode;
import com.fang.security.common.base.ServiceCode;

import java.io.Serializable;

/**
 * @Description
 * @Author Bernie
 * @Date 2024/4/7 14:08
 **/
public class JsonResult implements Serializable {

    private String statusCode;
    private String message;
    private Object data;

    public JsonResult(ResultCode resultCode) {
        this.statusCode = resultCode.getCode();
        this.message = resultCode.getMessage();
    }

    public JsonResult(String code, String message) {
        this.statusCode = code;
        this.message = message;
    }

    public JsonResult(ResultCode resultCode, Object data) {
        this.statusCode = resultCode.getCode();
        this.message = resultCode.getMessage();
        this.data = data;
    }

    //成功操作
    public static JsonResult success() {
        return new JsonResult(ServiceCode.SUCCESS);
    }

    public static JsonResult success(Object data) {
        return new JsonResult(ServiceCode.SUCCESS, data);
    }

    public static JsonResult fail() {
        return new JsonResult(ServiceCode.SYSTEM_BUSY);
    }

    public static JsonResult fail(String code, String message) {
        return new JsonResult(code, message);
    }

    public static JsonResult fail(ResultCode resultCode) {
        return new JsonResult(resultCode);
    }

    public static JsonResult fail(Object data) {
        return new JsonResult(ServiceCode.SYSTEM_BUSY, data);
    }

    public static JsonResult fail(ResultCode resultCode, Object data) {
        return new JsonResult(resultCode, data);
    }

//    ----------------------------------------------------

    public String getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(String statusCode) {
        this.statusCode = statusCode;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
